const commonDao = require('../../util/daoCommon');
const commonUtils = require('../../util/commonUtils');

const dao = {
    handleGetService: () => {
        let sql;
        sql = "select service_id,service_name,service_logo from service where is_delete='0'";
        return commonDao.selectCommon(sql);
    },
    handleGetServiceById: (data) => {
        let sql;
        sql = "select service_id,service_name,service_logo,service_introduce from service where is_delete='0' and service_id=$service_id";
        return commonDao.selectCommon(sql, data);
    },
    handleAddAppointment: (data) => {
        let sql;
        let appointment_id = commonUtils.genUUID();
        let date = new Date();
        let appointment_time = date.toLocaleString();
        data.appointment_id = appointment_id;
        data.appointment_time = appointment_time;
        sql = "insert into appointment values($appointment_id,$service_id,$appointment_people,$appointment_phone,$appointment_time,$appointment_remark,'0',$appointment_time,null,null,null,'0',$openId)";
        return commonDao.queryCommon(sql, data);
    },
    handleGetAppointmentByOpenId: (data) => {
        let sql;
        sql = "select s.service_name, a.appointment_phone,a.appointment_time,a.appointment_remark,a.appointment_state from appointment a inner join service s on a.service_id=s.service_id and a.wx_openId=$openId and a.is_delete='0'";
        return commonDao.selectCommon(sql, data);
    }
};
module.exports = dao;